//
//  AreaModel.swift
//  shop
//
//  Created by 刘伟 on 2017/4/21.
//
//

struct AreaModel {
    var id: Int! = 0
    var province: String! = ""
    var city: String! = ""
    var district: String! = ""
}

struct ProvinceModel {
    var id: Int!
    var text: String!
    var children = Array<CityModel>()
    
    init(data: [String: AnyObject]) {
        for key in data.keys {
            if key == "value" {
                self.id = data["value"] as! Int
            }
            if key == "text" {
                self.text = data["text"] as! String
            }
            if key == "children" {
                let chilrenData = data["children"] as! [[String: AnyObject]]
                for child in chilrenData {
                    let city = CityModel(data: child)
                    self.children.append(city)
                }
            }
        }
    }
}


struct CityModel {
    var id: Int!
    var text: String!
    var children = Array<DistrictModel>()
    
    init(data: [String: AnyObject]) {
        for key in data.keys {
            if key == "value" {
                self.id = data["value"] as! Int
            }
            if key == "text" {
                self.text = data["text"] as! String
            }
            if key == "children" {
                let chilrenData = data["children"] as! [[String: AnyObject]]
                for child in chilrenData {
                    let district = DistrictModel(data: child)
                    self.children.append(district)
                }
            }
        }
    }
}

struct DistrictModel {
    var id: Int!
    var text: String!
    
    init(data: [String: AnyObject]) {
        for key in data.keys {
            if key == "value" {
                self.id = data["value"] as! Int
            }
            if key == "text" {
                self.text = data["text"] as! String
            }
        }
    }
}
